
from rest_framework import serializers
from django.contrib.auth.models import Group,Permission


class PermSimpleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Permission
        fields = [
            'id',
            'name'
        ]


class GroupModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = Group
        fields = [
            'id',
            'name',
            # ManyToManyField类型字段操作：g.permissions.set([<30权限对象>, <31权限对>, <32权限对象>])
            'permissions' # 前端传来的permissions=[30,31,32],模型类序列化器会自动帮助我们插入中间表数据
        ]